﻿using System;
using System.Linq.Expressions;
using SBACN.WebSite.Code;
using SBACN.WebSite.Models;

namespace SBACN.WebSite.Admin.AboutGuild
{
	public partial class CouncilList : AdminBasePage
	{
		/// <summary>
		/// 系统字典类型
		/// </summary>
		public string SystemType
		{
			get
			{
				//if (ViewState["SystemType"] == null)
				//    return "00010004";//默认值
				//else
				//    return ViewState["SystemType"].ToString();
				return this.SystemCode;
			}
			private set
			{
				ViewState["SystemType"] = this.SystemCode;
			}
		}
		public string TypeID { get; set; }
		protected void Page_Load(object sender, EventArgs e)
		{
			if (!IsPostBack)
			{
				ShowCouncillist(1);
			}
		}
		protected void ShowCouncillist(int pageIndex)
		{
			Expression<Func<TB_CouncilInfo, bool>> f = (p => true);
			Expression<Func<TB_CouncilInfo, DateTime>> order = (p => p.CreateDate);
			var records = 0;
			this.List.DataSource = DAL.DALHelper.Instance.GetList<TB_CouncilInfo, DateTime>(f, order, false, this.Pager1.PageSize, pageIndex, out records);
			DataBind();
			this.Pager1.RecordCount = records;
			this.Pager1.InitControl();
		}

		public void BindSelectedPageIndexChanged(int pageIndex, int nextPage)
		{
			ShowCouncillist(nextPage);
		}

		protected void Close_Click(object sender, EventArgs e)
		{
			int CID = 0;
			if (Int32.TryParse(this.Hid_ID.Value, out CID))
			{
				Expression<Func<TB_CouncilInfo, bool>> f = (p =>p.Status);
				var resultCR = DAL.DALHelper.Instance.GetList<TB_CouncilInfo>(f);
				foreach (var l in resultCR)
				{
					l.Status = false;
					DAL.DALHelper.Instance.Update<TB_CouncilInfo>(l);
				}

				var resultC = DAL.DALHelper.Instance.GetObject<TB_CouncilInfo>("Index", CID);
				resultC.Status = true;
				DAL.DALHelper.Instance.Update<TB_CouncilInfo>(resultC);

				DAL.DALHelper.Instance.SaveChanges();
				ClientScript.RegisterClientScriptBlock(this.GetType(),"AlertMsg","<script type='text/javascript'>alert('理事会启用成功！');location=location;</script>");
				return;
			}
			else
			{
				ClientScript.RegisterClientScriptBlock(this.GetType(),"AlertMsg","<script type='text/javascript'>alert('理事会启用失败！请刷新后重新启用。');location=location;</script>");
				return;
			}
		}

		protected void btn_NewsRefresh_Click(object sender, EventArgs e)
		{
			ShowCouncillist(this.Pager1.CurrentPageIndex);
		}
	}
}